/*
============================================================================
 Name        : RssFeed.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : TRssFeed implementation
============================================================================
*/

#include "RssFeed.h"
#include "PluginUtility.h"

_LIT(KRssFeedEmptyField, "");

TItemEnclosure::TItemEnclosure()
: iUrl(NULL), iType(NULL), iLength(0)
{
}

TItemEnclosure::~TItemEnclosure()
{
	DELETE(iUrl);
	DELETE(iType);
}

const TDesC& TItemEnclosure::Url() const
{
	if (iUrl) return *iUrl;
	return KRssFeedEmptyField;
}

void TItemEnclosure::SetUrl(const TDesC& aUrl)
{
	DELETE(iUrl);
	iUrl = aUrl.Alloc();
}

const TInt TItemEnclosure::Length() const
{
	return iLength;
}
void TItemEnclosure::SetLength(const TInt aLength)
{
	iLength = aLength;
}

const TDesC& TItemEnclosure::Type() const
{
	if (iType) return *iType;
	return KRssFeedEmptyField;
}

void TItemEnclosure::SetType(const TDesC& aType)
{
	DELETE(iType);
	iType = aType.Alloc();
}

TRssFeedItem::TRssFeedItem()
: iTitle(NULL), iDescription(NULL), iEnclosure(NULL)
{
}

TRssFeedItem::~TRssFeedItem()
{
	DELETE(iTitle);
	DELETE(iDescription);
	DELETE(iEnclosure);
}

const TDesC& TRssFeedItem::Title() const
{
	if (iTitle) return *iTitle;
	return KRssFeedEmptyField;
}

void TRssFeedItem::SetTitle(const TDesC& aTitle)
{
	DELETE(iTitle);
	iTitle = aTitle.Alloc();
}

const TDesC& TRssFeedItem::Description() const
{
	if (iDescription) return *iDescription;
	return KRssFeedEmptyField;
}

void TRssFeedItem::SetDescription(const TDesC& aDescription)
{
	DELETE(iDescription);
	iDescription = aDescription.Alloc();
}

const TItemEnclosure& TRssFeedItem::Enclosure() const
{
	return *iEnclosure;
}

void TRssFeedItem::SetEnclosure(TItemEnclosure* aEnclosure)
{
	DELETE(iEnclosure);
	iEnclosure = aEnclosure;
}

TBool TRssFeedItem::IsPlayable()
{
	if (!iEnclosure) return EFalse;
	if (iEnclosure->Url().Length() == 0) return EFalse;
	
	//return (iEnclosure->Url().Right(3).CompareF(_L("mp3")) == 0);
	return ETrue;
}

TRssFeed::TRssFeed()
: iTitle(NULL), iDescription(NULL), iImageUrl(NULL)
{
}

TRssFeed::~TRssFeed()
{
	DELETE(iTitle);
	DELETE(iDescription);
	DELETE(iImageUrl);

	iItems.ResetAndDestroy();
}

const TDesC& TRssFeed::Title() const
{
	if (iTitle)	return *iTitle;
	return KRssFeedEmptyField;
}

void TRssFeed::SetTitle(const TDesC& aTitle)
{
	DELETE(iTitle);
	iTitle = aTitle.Alloc();
}

const TDesC& TRssFeed::Description() const
{
	if (iDescription) return *iDescription;
	return KRssFeedEmptyField;
}

void TRssFeed::SetDescription(const TDesC& aDescription)
{
	DELETE(iDescription);
	iDescription = aDescription.Alloc();
}

const TDesC& TRssFeed::ImageUrl() const
{
	if (iImageUrl) return *iImageUrl;
	return KRssFeedEmptyField;
}

void TRssFeed::SetImageUrl(const TDesC& aImageUrl)
{
	DELETE(iImageUrl);
	iImageUrl = aImageUrl.Alloc();
}

RPointerArray<TRssFeedItem> TRssFeed::GetItems()
{
	return iItems;
}

void TRssFeed::AppendItemL(TRssFeedItem* aItem)
{
	iItems.AppendL(aItem);
}